/*
 * ClientServer.java
 *
 * Created on 29 de Julho de 2007, 16:36
 */

package org.gpp.proj1.ui.gui.lobby;

import org.gpp.proj1.ui.gui.SRGGUIView;

/**
 *
 * @author  Gustavo
 */
public class SCRClientServer extends javax.swing.JFrame {
    
    /**
	 * 
	 */
	private static final long serialVersionUID = 8590666208126195681L;
	private final SRGGUIView view;
	
	/** Creates new form ClientServer */
    public SCRClientServer(SRGGUIView view) {
        this.view = view;
		initComponents();
        this.setLocationRelativeTo(null);
    }
    
    /** Creates new form ClientServer */
    public SCRClientServer( SRGGUIView view, String errorMessage ) {
        this( view );
        this.errorMessageLabel.setText( errorMessage );
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        instructionLabel = new javax.swing.JLabel();
        connectButton = new javax.swing.JButton();
        createButton = new javax.swing.JButton();
        backButton = new javax.swing.JButton();
        errorMessageLabel = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("SomeRobotGame");
        setResizable(false);
        instructionLabel.setText("Connect to a server or create one");

        connectButton.setText("Connect to server");
        connectButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                connectButtonActionPerformed(evt);
            }
        });

        createButton.setText("Create server");
        createButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                createButtonActionPerformed(evt);
            }
        });

        backButton.setText("<< Back");
        backButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                backButtonActionPerformed(evt);
            }
        });

        errorMessageLabel.setText(" ");

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(instructionLabel)
                    .add(backButton))
                .addContainerGap(174, Short.MAX_VALUE))
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .add(99, 99, 99)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, createButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 153, Short.MAX_VALUE)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, connectButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 153, Short.MAX_VALUE))
                .add(96, 96, 96))
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(errorMessageLabel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 328, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(instructionLabel)
                .add(39, 39, 39)
                .add(connectButton)
                .add(20, 20, 20)
                .add(createButton)
                .add(49, 49, 49)
                .add(errorMessageLabel)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 22, Short.MAX_VALUE)
                .add(backButton)
                .addContainerGap())
        );
        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void backButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_backButtonActionPerformed
        this.view.showMainWindow();
        this.dispose();
    }//GEN-LAST:event_backButtonActionPerformed

    private void createButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_createButtonActionPerformed
        SCRConfigureServer cs = new SCRConfigureServer(this.view);
        cs.setLocationRelativeTo(null);
        cs.setVisible(true);
        this.dispose();
    }//GEN-LAST:event_createButtonActionPerformed

    private void connectButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_connectButtonActionPerformed
        SCRServerConnection sc = new SCRServerConnection(this.view);
        sc.setLocationRelativeTo(null);
        sc.setVisible(true);
        this.dispose();
    }//GEN-LAST:event_connectButtonActionPerformed
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton backButton;
    private javax.swing.JButton connectButton;
    private javax.swing.JButton createButton;
    private javax.swing.JLabel errorMessageLabel;
    private javax.swing.JLabel instructionLabel;
    // End of variables declaration//GEN-END:variables
    
}
